<template>
	<!-- 电梯信息管理/公告 -->
	<div class="operationBox heightMax publicbox duiBox" v-loading='loading'>
		<el-row :gutter="10">
			<el-col :span="1.5">
				<el-button type="success" @click='newAdd(1)' size="mini">新建滚动内容</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="primary" :disabled="disableBtn" @click='newAdd(2)' size="mini">编辑滚动内容</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="success" :disabled="disableBtn" @click='newAdd(3)' size="mini">滚动内容详情</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="danger" :disabled="disableBtn" @click='remove(1)' size="mini">删除滚动内容</el-button>
			</el-col>
			<div class="fr">
				<el-button size="mini" @click='goBack'>返回</el-button>
			</div>
		</el-row>
		<div class="duiBoxMess">
			<el-row>
				<el-col :span="6">
					<!-- <span class="messTit font15">队列编号：</span><span class="mess font14"></span> -->
				</el-col>
				<el-col :span="6">
					<div class="messBoxC">
						<span class="messTit font15">队列名称：</span><span class="mess font14">{{currentRowList.name}} </span>
					</div>
				</el-col>
				<el-col :span="6">
					<div class="messBoxC">
						<span class="messTit font15">队列描述：</span><span class="mess font14">{{currentRowList.qdesc}}</span>
					</div>
				</el-col>
				<el-col :span="6">
					<div class="messBoxC">
						<span class="messTit font15">适用终端：</span><span class="mess font14">{{currentRowList.ttypeName}}</span>
					</div>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="6">
					<div class="messBoxC">
						<span class="messTit font15">创建用户：</span><span class="mess font14">{{currentRowList.create_user}}</span>
					</div>
				</el-col>
				<el-col :span="6">
					<div class="messBoxC">
						<span class="messTit font15">创建时间：</span><span class="mess font14">{{currentRowList.create_time}}</span>
					</div>
				</el-col>
				<el-col :span="6">
					<div class="messBoxC">
						<span class="messTit font15">修改用户：</span><span class="mess font14">{{currentRowList.update_user}}</span>
					</div>
				</el-col>
				<el-col :span="6">
					<div class="messBoxC">
						<span class="messTit font15">修改时间：</span><span class="mess font14">{{currentRowList.update_time}}</span>
					</div>
				</el-col>
			</el-row>
		</div>
		<div class="tableBox">
			<vueScroll>
				<el-table :data="tableData" highlight-current-row ref="moviesTable" @row-click="rowClick" @select-all="selectChange"
				 @selection-change="selectChange" style="width: 100%" border header-row-class-name='tableHeader'>
					<el-table-column type="index" class="over" fixed>
					</el-table-column>
					<el-table-column type="selection" min-width="50" fixed>
					</el-table-column>
					<el-table-column label="公告类型" max-width="140">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.ntypeName" placement="top">
								<span class="speSpan">{{scope.row.ntypeName}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="是否停用" max-width="140">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.is_disabledName"
							 placement="top">
								<span class="speSpan">{{scope.row.is_disabledName}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="播放开始日期" max-width="140">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.start_day" placement="top">
								<span class="speSpan">{{scope.row.start_day}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="播放结束日期" max-width="140">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.end_day" placement="top">
								<span class="speSpan">{{scope.row.end_day}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
				</el-table>
				<!-- 分页器 -->
				<div class="pag">
					<el-pagination :current-page="page" :page-sizes="[10, 20, 30, 40]" :page-size="page_size" layout="total, sizes, prev, pager, next, jumper"
					 :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange">
					</el-pagination>
				</div>
			</vueScroll>
		</div>
		<dialogCom v-if='dialogShow' :rowId='rowId' :currentMode='currentMode' :dialogVisible='dialogShow' :title='title'
		 :ensureLoading='btnLoading' @closeMask='closeMask' @submitDialog='submitDialog'></dialogCom>
	</div>
</template>

<script>
	import {
		loadFn,
		axiosPost,
		axiosGet,
		axiosDelete,
		axiosPut,
		moment
	} from "@/common.js";
	import dialogCom from "./add.vue"
	export default {
		activated() {},
		mounted() {
			this.getTableList()
		},
		components: {
			dialogCom,
		},
		data() {
			return {
				btnType: 'primary',
				showVis: false,
				showProp: true,
				btnLoading: false,
				marketingCode: '',
				tableData: [],
				page: 1,
				page_size: 10,
				total: 0,
				loading: true,
				query: '',
				dialogShow: false,
				title: '',
				disableBtn: true,
				checkBoxArr: [],
				rowId: 0,
				disableBtnAll: true,
				removePic: true,
				resource: '',
				resourceArr: [{
					label: '图片',
					value: 1
				}, {
					label: '视频',
					value: 2
				}],
				playMode: '',
				playModeArr: [{
					label: '纯视频',
					value: 1
				}, {
					label: '1/2视频',
					value: 2
				}, {
					label: '1/3视频',
					value: 3
				}, {
					label: '纯图片',
					value: 4
				}, {
					label: '1/2图片',
					value: 5
				}, {
					label: '1/3图片',
					value: 6
				}],
				terminal: '',
				terminalArr: [{
					label: '单屏',
					value: 1
				}, {
					label: '双屏',
					value: 2
				}],
				startKb: '',
				endKb: '',
				endDisabled: true,
				removeId: '',
				currentMode: '0'
			}
		},
		computed: {
			BroadcastManageId() {
				if (localStorage.BroadcastManageId) {
					return JSON.parse(localStorage.BroadcastManageId).id
				} else {
					return ''
				}
			},
			currentRowList() {
				if (localStorage.currentRowList) {
					return JSON.parse(localStorage.currentRowList).id
				} else {
					return ''
				}
			},
		},
		methods: {
			goBack() {
				let obj = {
					name: '播放管理',
					router: '/MainView/ReleaseManagement/BroadcastManage'
				}
				this.$store.commit('GOTAGROUTER', obj)
			},
			inputChange(val) {
				if (val) {
					this.endDisabled = false
				} else {
					this.endDisabled = true
					this.endKb = ''
				}
			},
			closeVis() {
				this.showVis = false
				if (this.playMode || this.terminal || this.startKb) {
					this.btnType = 'warning'
				} else {
					this.btnType = 'primary'
				}
			},
			pubLickSearch() {
				if (this.playMode || this.terminal || this.startKb) {
					this.btnType = 'warning'
					this.showVis = true
				} else {
					this.btnType = 'primary'
					this.showVis = false
				}
			},
			remove(val) {
				this.$confirm('此操作将永久删除该滚动, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					let url = ''
					let data = {

					}
					let arr = this.checkBoxArr.map((item) => {
						return item.id
					})
					console.log(arr)
					if (val == 1) {
						url = '/res/queue/material/' + this.rowId + '/'

					} else {
						url = '/res/queue/material/'
						data = {
							ids: arr
						}
					}
					axiosDelete(url, data, (res) => {
						if (res.code == 0) {
							this.$message.success('删除成功')
							this.getTableList()
						} else {
							this.$message.error(res.detail.result)
						}
					})
				}).catch(() => {

				});
			},
			//新建资源
			newAdd(value) {
				this.dialogShow = true
				console.log(this.dialogShow)
				if (value == 1) {
					this.rowId = 0
					this.title = '新建滚动内容'
				} else if (value == 2) {
					this.title = '编辑滚动内容'
				} else if (value == 3) {
					this.title = '滚动滚动内容详情'
				}
			},
			submitDialog() {
				this.dialogShow = false
				this.getTableList()
			},
			//关闭添加弹窗
			closeMask(value) {
				this.dialogShow = false
				if (value == 2) {
					this.getTableList()
				}
			},
			//获取表格数据
			getTableList() {
				this.pubLickSearch()
				this.showVis = false
				this.loading = true
				let params = {
					page: this.page,
					page_size_count: this.page_size,
					play_queue: this.BroadcastManageId
				}
				let url = '/res/queue/material/'
				this.axiosGet(url, params, (res) => {
					this.loading = false
					if (res.code == 0) {
						this.total = res.detail.count
						this.tableData = res.detail.results
						this.tableData.map((item) => {
							if (item.ntype == '0') {
								item.ntypeName = '常驻公告'
							} else if (item.ntype == '1') {
								item.ntypeName = '临时公告'
							}
							if (item.dtype == '0') {
								item.dtypeName = '文字'
							}
							if (item.is_disabled == '0') {
								item.is_disabledName = '不是'
							}else if(item.is_disabled == '1'){
								item.is_disabledName = '是'
							}
							item.retention_timeName = item.retention_time.toString()
						})
					} else {
						this.$message.error(res.detail.result)
					}
				})
			},
			find() {
				this.page = 1
				this.page_size = 10
				this.getTableList()
			},
			reset() {
				this.startKb = ''
				this.endKb = ''
				this.terminal = ''
				this.playMode = ''
				this.showVis = false
				this.resource = ''
				this.page = 1
				this.page1 = 1
				this.page_size = 10
				this.page_size1 = 10
				this.query = ''
				this.getTableList()
			},
			//表格
			rowClick(row, column, event) {
				this.$refs.moviesTable.toggleRowSelection(row)
			},
			selectChange(res) {
				console.log(res)
				if (res.length == 1) {
					this.disableBtn = false
					this.rowId = res[0].id
					this.currentMode = res[0].play_mode
				} else {
					this.disableBtn = true
				}
				if (res.length > 1) {
					this.disableBtnAll = false
				} else {
					this.disableBtnAll = true
				}
				this.checkBoxArr = res
			},
			selectChange1(res) {
				if (res.length == 1) {
					this.removeId = res[0].id
					this.removePic = false
				} else {
					this.removeId = ''
					this.removePic = true
				}
			},
			//分页器
			handleSizeChange(size) {
				this.page_size = size
				this.getTableList()
			},
			handleCurrentChange(page) {
				this.page = page
				this.getTableList()
			},
		},
	}
</script>

<style scoped lang="less">
	.colItem {
		display: flex;
		flex-direction: row;

		.searchCode {
			display: flex;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			width: 120px;
		}
	}

	.tableBox {
		height: 80%;
		overflow-y: auto;
	}

	.listName {
		display: flex;
		justify-content: flex-start;
		text-align: left;
		height: 25px;
		align-items: center;

		i {
			width: 3px;
			height: 60%;
			background: #2d8cf0;
			margin: 10px 5px;
		}

	}

	.marginTop5 {
		display: inline-block;
		margin-top: 5px;
	}

	.duiBoxMess {
		padding: 10px;
		box-sizing: border-box;
		margin-bottom: 10px;
		border-radius: 5px;
		background: #409EFF;
		padding-left: 30px;

		.messTit {
			color: #fff;
		}

		.mess {
			color: #fff;
		}
	}

	.messBoxC {
		text-align: left;
	}
</style>
